﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace laba2.Entity
{
    public class PrincipleOfRatingByDate:Entity
    {
        private List<RatingByDate> _ratingByDates = new List<RatingByDate>();

        public PrincipleOfRatingByDate(int id, List<RatingByDate> ratingByDates) : base(id)
        {
            _ratingByDates = ratingByDates;
        }

        public PrincipleOfRatingByDate( List<RatingByDate> ratingByDates)
        {
            _ratingByDates = ratingByDates;
        } 

        public PrincipleOfRatingByDate()
        {
        }

        
        public PrincipleOfRatingByDate(int id) : base(id)
        {
        }

        public  List<RatingByDate> RatingByDates
        {
            get { return _ratingByDates; }
            set { _ratingByDates = value; }
        }

        public int GetRating(DateTime date, PracticalTask task)
        {
            int delay = date.Subtract(task.Deadline).Days;
            return _ratingByDates.OrderBy(ratingByDate => ratingByDate.Delay).
                Where(ratingByDate => ratingByDate.Delay >= delay).FirstOrDefault().Rating;
        }


        public void Add( int delay, int rating)
        {
            _ratingByDates.Add(new RatingByDate(delay, rating));
        }
    }
}
